package com.zrrd.learn.chapter08面向对象.objectoriented02;

import java.util.Scanner;

/**
 * 1题测试类
 *
 * @author wrn
 * @version 1.0
 * @date 2023/7/24 22:07
 */

public class Test01 {

    public static void main(String[] args) {
        GirlFriend[] arr = new GirlFriend[4];
        //2.创建对象键盘录入
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            //创建对象
            GirlFriend g = new GirlFriend();
            //录入姓名
            System.out.println("请输入第" + (i+1) + "个女孩的名字");
            String name = sc.next();
            g.setName(name);
            //录入年龄
            System.out.println("请输入第" + (i+1) + "个女孩的年龄");
            int age = sc.nextInt();
            g.setAge(age);
            //录入性别
            g.setSex("女");
            //录入爱好
            System.out.println("请输入第" + (i+1) + "个女孩的爱好");
            String hobby = sc.next();
            g.setHobby(hobby);
            arr[i] = g;
        }
        int sum = 0;

        for (int j = 0; j < arr.length; j++) {
            //添加索引
            GirlFriend gf = arr[j];
            sum = sum + gf.getAge();

        }
        //4.求平均值
        int avg = 0;
        avg = sum / arr.length;
        System.out.println("平均年龄为" + avg);
        //5.统计年龄比平均值较小的并打印
        for (int k = 0; k < arr.length; k++) {
            GirlFriend gf = arr[k];
            if (gf.getAge() < avg) {
                System.out.println("年龄小于平均年龄的为");
                System.out.println("姓名" + gf.getName() + "," + "年龄" + gf.getAge() + "," + "性别" + gf.getSex() + "," + "爱好" + gf.getHobby());
            }
        }


    }
}
